package com.overoid.mynote;

import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.overoid.mynote.R;
import com.overoid.mynote.data.DBHelper;
import com.overoid.mynote.data.DBHelper.MemoClass;

public class MainActivity extends ListActivity {
    private static final String CLASSNAME = MainActivity.class.getSimpleName();
    
    private ImageButton searchButton;
    private ImageButton writeButton;
    private EditText searchKeyword;
    private TextView empty;
    
    private DBHelper db;
    private MemoListAdapter memoListAdapter;
    private List<MemoClass> memoClasses;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Log.v(Constants.LOGTAG, MainActivity.CLASSNAME + " onCreate()");
        setContentView(R.layout.main);

        this.searchButton = (ImageButton)findViewById(R.id.memo_search);
        this.searchKeyword = (EditText)findViewById(R.id.memo_search_keyword);
        this.writeButton = (ImageButton)findViewById(R.id.memo_write);
        this.empty = (TextView)findViewById(R.id.memo_list_empty);
        
        // set list properties
        final ListView listView = getListView();
        listView.setItemsCanFocus(false);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setEmptyView(this.empty);

    }
    
    @Override
    protected void onResume() {
        super.onResume();
        Log.v(Constants.LOGTAG, MainActivity.CLASSNAME + " onResume()");
        
        // after db query, MemoClass List Adapter Binding
        db = new DBHelper(getApplicationContext());
        this.memoClasses = db.getMemoClassList();
        
        if(memoClasses == null || memoClasses.size() == 0) {
        	empty.setText("No Data");
        }
        else {
        	this.memoListAdapter = new MemoListAdapter(getApplicationContext(),memoClasses);
        	this.setListAdapter(memoListAdapter);
        }
        
    }

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
	}
    
    
    
}